using System.Collections.Generic;
using System.IO;
using DocumentFormat.OpenXml.Packaging;
using SharePoint.Security.DocHelpers.ExportFormats;

namespace SharePoint.Security.ContentScanner.Engine.Analyzers
{
    public class WordDocumentScanner : BaseDocumentScanner
    {
        public WordDocumentScanner()
        {
            DocQualifier = "Word Doc";
        }

        public override List<ScanResult> Scan(string tempDocPath, List<Pattern> patterns, string fileFullPath)
        {
            using (var wordDoc = WordprocessingDocument.Open(tempDocPath, true))
            {
                string docText;

                CheckProperties(wordDoc, patterns, fileFullPath, "MetaData", DocQualifier);

                using (var sr = new StreamReader(wordDoc.MainDocumentPart.GetStream()))
                {
                    docText = sr.ReadToEnd();
                }

                SearchRegExpString(docText, patterns, fileFullPath, "", DocQualifier);
            }

            return Results;
        }
    }
}